const Koa = require('koa')

// const Router = require('koa-router')
const { koaBody } = require('koa-body');
const cors = require('koa2-cors')

const router = require('../router/index')


//请求错误
const error = require('../app/errorType')

const http = require('http')

const app = new Koa()

const { initSocketio } = require('../utils/socket')
app.use(koaBody()).use(router.routes()).use(cors())

app.on('error', error)

//把koa实例挂载到server上
const server = http.createServer(app.callback())

//传入server 配置socket实例
initSocketio(server)


module.exports = server